/*
 * Contains a dictionary of all the rules from the parser xml
 */

package com.querie.parser;

import java.util.List;
import java.util.Collections;
import java.util.ArrayList;

/**
 *
 * @author a-skoshy
 */
public class RuleDictionary {
	private Rule columnRule;
	private Rule tableRule;
	private Rule whereRule;
	private Rule orderRule;
	private Rule havingRule;
	private Rule groupRule;

	public RuleDictionary(List<Rule> rules){

		Rule rule = null;

		for(int i = 0; i < rules.size(); i++){
			rule = rules.get(i);
			if("COLUMNSTRING".equals(rule.getName())){
				columnRule = rule;
			}else if("TABLESTRING".equals(rule.getName())){
				tableRule = rule;
			}else if("WHERESTRING".equals(rule.getName())){
				whereRule = rule;
			}else if("ORDERBYSTRING".equals(rule.getName())){
				orderRule = rule;
			}else if("GROUPBYSTRING".equals(rule.getName())){
				groupRule = rule;
			}else if("HAVINGSTRING".equals(rule.getName())){
				havingRule = rule;
			}

		}
	}

	public Rule getColumnRule(){
		return columnRule;
	}

	public Rule TableRule(){
		return tableRule;
	}

	public Rule getWhereRule(){
		return whereRule;
	}

	public Rule getOrderRule(){
		return orderRule;
	}

	public Rule getGroupRule(){
		return groupRule;
	}

	public Rule gethavingRule(){
		return havingRule;
	}


	public Rule getKeywordRule(String keyword){
		if(keyword.equals("SELECT")){
			return getColumnRule();
		}else if(keyword.equals("FROM")){
			return TableRule();
		}else if(keyword.equals("WHERE")){
			return getWhereRule();
		}else if(keyword.equals("ORDERBY")){
			return getOrderRule();
		}else if(keyword.equals("GROUPBY")){
			return getGroupRule();
		}else if(keyword.equals("HAVING")){
			return gethavingRule();
		}else return null;
	}


	public String toString(){
		return columnRule + ":" + tableRule+ ":" + whereRule + ":" + orderRule + ":" + groupRule + ":" + havingRule;
	}

}
